package com.gulimall.cart.vo;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author coder_ccy
 * @date 2022/4/2 16:58
 */

@Slf4j
public class CartVo {


    @Getter
    @Setter
    List<CartItemVo> items;

    /**
     * 商品数量
     */
    private Integer countNum;



    /**
     * 商品总价
     */
    private BigDecimal totalAmount;

    /**
     * 减免价格
     */
    private BigDecimal reduce = new BigDecimal("0.00");


    public Integer getCountNum() {
        int count = 0;
        for (CartItemVo item : items) {
            count+=item.getCount();
        }
        return count;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal total = new BigDecimal("0.00");

        if(items!=null && items.size()>0) {
            for (CartItemVo item : items) {
                total = total.add(item.getTotalPrice());
            }
        }
        log.info("????????????????"+total);

        return total;
    }
}
